package com.ojoin.trade.t0loan_core.web.dao.impl;

import java.util.HashMap;
import java.util.List;

import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

import com.ojoin.trade.common.constdef.IConstDef;
import com.ojoin.trade.common.exception.BusinessException;
import com.ojoin.trade.common.exception.DaoException;
import com.ojoin.trade.common.web.dao.impl.BaseDaoImpl;
import com.ojoin.trade.t0loan_core.web.dao.TbPosTranscationLogDao;
import com.ojoin.trade.t0loan_core.web.domain.TbPosTranscationLog;

@Repository
public class TbPosTranscationLogDaoImpl extends
		BaseDaoImpl<TbPosTranscationLog> implements TbPosTranscationLogDao {

	public List<TbPosTranscationLog> queryAllNoT1LoanPosTransInfoListByPayUserID(
			 int joinuserid, String transdate) throws BusinessException {
		String mapMethodName = "queryAllNoT1LoanPosTransInfoListByPayUserID";
		try {
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("joinuserid", joinuserid);
			paramMap.put("transdate", transdate);

			return sqlSessionTemplate.selectList(
						getSqlName(mapMethodName),
						paramMap);
		} catch (Exception e) {
			throw new DaoException(String.format("查询对象列表出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
	}
	
	@Override
	public List<TbPosTranscationLog> queryT0LoanLiveUserHistoryPosTransListByMhtNo(String mhtno, Pageable page)
			throws BusinessException {
		String mapMethodName = "queryT0LoanLiveUserHistoryPosTransListByMhtNo";
		try {
			if (page.getPageNumber() == IConstDef.PageAll && page.getPageSize() == IConstDef.PageAll) {
				return sqlSessionTemplate.selectList(getSqlName(mapMethodName), mhtno, this.getPageBounds(page));
			} else {
				return sqlSessionTemplate.selectList(getSqlName(mapMethodName), mhtno);
			}
		} catch (Exception e) {
			throw new DaoException(String.format("查询申请T+0贷款审核通过的九盈用户的当日前30日历史交易列表出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
	}

	@Override
	public TbPosTranscationLog queryT1LoanPosTransInfoSumByPayUserID(
			int joinuserid, String transdate) throws BusinessException {

		String mapMethodName = "queryT1LoanPosTransInfoSumByPayUserID";
		try {
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("joinuserid", joinuserid);
			paramMap.put("transdate", transdate);

			return sqlSessionTemplate.selectOne(
						getSqlName(mapMethodName),
						paramMap);
		} catch (Exception e) {
			throw new DaoException(String.format("查询对象列表出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
	
	}

	@Override
	public void deleteByIdInBatch(Integer joinuserid, String transdate) throws BusinessException {
		String mapMethodName = "deleteByIdInBatch";
		try {
			HashMap<String, Object> paramMap = new HashMap<String, Object>();
			paramMap.put("joinuserid", joinuserid);
			paramMap.put("transdate", transdate);

			sqlSessionTemplate.selectList(getSqlName(mapMethodName), paramMap);
		} catch (Exception e) {
			throw new DaoException(String.format("批量删除pos交易记录出错！语句：%s",
					getSqlName(mapMethodName)), e);
		}
	}
	
}
